package resource;

import java.io.FileReader;
import java.util.HashMap;

import javax.xml.parsers.SAXParserFactory;

import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.xml.sax.InputSource;

import resource.handler.MusicHandler;

public class MusicManager {

	HashMap<String, String> l_m;
	public MusicManager(String file){
		l_m = new HashMap<String, String>();
		javax.xml.parsers.SAXParserFactory spf = SAXParserFactory.newInstance();
		spf.setValidating(false);
		javax.xml.parsers.SAXParser sp;
		try {
			sp = spf.newSAXParser();
			org.xml.sax.InputSource input = new InputSource(new FileReader(file));
			MusicHandler handler = new MusicHandler(l_m);
			sp.parse(input, handler);
		} catch (Exception e) {
			e.printStackTrace();
		};
	}

	public Music getMusic(String key){
		try {
			return new Music(l_m.get(key));
		} catch (SlickException e) {
			e.printStackTrace();
			return null;
		}
	}
}
